<template>
	<el-container>
		<el-header>
			<div class="left-panel">
                <el-button type="warning" @click="batch_remove" v-auth="'stock.remove'">一键清零</el-button>
				<sc-export-button :apiObj="apiObj" :search="search"></sc-export-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
                    <el-select v-model="search.ware_id" filterable placeholder="仓库" @change="inChange" clearable>
                        <el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id" />
                    </el-select>
					<el-input v-model="search.goods_name" placeholder="产品型号" clearable @keyup.enter="upsearch"></el-input>
					<!-- <el-input v-model="search.goods_code" placeholder="产品编号" clearable @keyup.enter="upsearch"></el-input> -->
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="#" type="index" width="50" align="center"></el-table-column>
					<el-table-column label="产品型号" prop="goods.goods_model" align="center"></el-table-column>
                    <el-table-column label="颜色" prop="color_name" align="center"></el-table-column>
                    <el-table-column label="方向" prop="direction_name" align="center"></el-table-column>
					<el-table-column label="速比" prop="goods.speed_ratio.name" align="center"></el-table-column>
					<el-table-column label="法兰" prop="goods.flange.name" align="center"></el-table-column>
					<el-table-column label="孔数" prop="goods.hole" align="center"></el-table-column>
                    <el-table-column label="仓库" prop="ware.ware_name" align="center"></el-table-column>
                    <el-table-column label="库存数量" prop="curr_stock" align="center">
                        <template #default="{row}">
                            <div :style="'color:' + (row.curr_stock < row.goods.low_inventory_warning ? '#F00' : '')">{{row.curr_stock}}</div>
                        </template>
                    </el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
	import saveDialog from './save'

	export default {
		name: '查询1',
		components: {
			saveDialog
		},
		data() {
			return {
				dialog: {
					save: false
				},
				apiObj: this.$API.goods.stock,
				selection: [],
				search: {
					ware_id: null
				},
                wareList:[],
			}
		},
        mounted() {
            this.getWare()
		},
		methods: {
			//表格选择后回调事件
			selectionChange(selection){
				this.selection = selection;
			},
			//搜索
			upsearch(){
				this.$refs.table.upData(this.search)
			},
            // 获取仓库
            async getWare(){
                var res = await this.$API.goods.ware.all.get();
                this.wareList = res.data;
            },
            async batch_remove(){
				this.$confirm(`确定一键全部库存吗？确定后会将负库存数量归零,是否继续?`, '提示', {
					type: 'warning'
				}).then(async () => {
                    var res = await this.$API.ware.clearedStock.post();
                    if(res.code == 1){
                        this.$refs.table.refresh()
                        this.$message.success("删除成功")
                    }else{
                        this.$alert(res.message, "提示", {type: 'error'})
                    }
				}).catch(() => {

				})
			},
		}
	}
</script>

<style>
</style>
